package com.lxmes.hr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.hr.domain.NcRePunSummary;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.hr.domain.NcGsjs;
import com.lxmes.hr.service.INcGsjsService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 个税计算Controller
 *
 * @author ruoyi
 * @date 2023-01-16
 */
@RestController
@RequestMapping("/hr/gsjs")
public class NcGsjsController extends BaseController
{
    @Autowired
    private INcGsjsService ncGsjsService;

    /**
     * 查询个税计算列表
     */
    @PreAuthorize("@ss.hasPermi('hr:gsjs:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcGsjs ncGsjs)
    {
        startPage();
        List<NcGsjs> list = ncGsjsService.selectNcGsjsList(ncGsjs);
        return getDataTable(list);
    }

    /**
     * 导出个税计算列表
     */
    @PreAuthorize("@ss.hasPermi('hr:gsjs:export')")
    @Log(title = "个税计算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcGsjs ncGsjs)
    {
        List<NcGsjs> list = ncGsjsService.selectNcGsjsList(ncGsjs);
        ExcelUtil<NcGsjs> util = new ExcelUtil<NcGsjs>(NcGsjs.class);
        util.exportExcel(response, list, "个税计算数据");
    }

    /**
     * 获取个税计算详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:gsjs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncGsjsService.selectNcGsjsById(id));
    }

    /**
     * 新增个税计算
     */
    @PreAuthorize("@ss.hasPermi('hr:gsjs:add')")
    @Log(title = "个税计算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcGsjs ncGsjs)
    {
        return toAjax(ncGsjsService.insertNcGsjs(ncGsjs));
    }

    /**
     * 修改个税计算
     */
    @PreAuthorize("@ss.hasPermi('hr:gsjs:edit')")
    @Log(title = "个税计算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcGsjs ncGsjs)
    {
        return toAjax(ncGsjsService.updateNcGsjs(ncGsjs));
    }

    /**
     * 删除个税计算
     */
    @PreAuthorize("@ss.hasPermi('hr:gsjs:remove')")
    @Log(title = "个税计算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncGsjsService.deleteNcGsjsByIds(ids));
    }

    @Log(title = "个税计算", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcGsjs> util = new ExcelUtil<>(NcGsjs.class);
        List<NcGsjs> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncGsjsService.imporIteminfo(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<NcGsjs> util = new ExcelUtil<>(NcGsjs.class);
        util.importTemplateExcel(response, "个税计算数据");
    }
}
